/**
 * Definition for singly-linked list. */
#include<map>
  struct ListNode {
      int val;
      ListNode *next;
      ListNode() : val(0), next(nullptr) {}
      ListNode(int x) : val(x), next(nullptr) {}
      ListNode(int x, ListNode *next) : val(x), next(next) {}
  };

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* slow = head;

        ListNode* fast = slow;
        ListNode* newhead = new ListNode(-1);
        std::map<int, int>hash;
        ListNode* cur = head;
        while (cur)
        {
            hash[cur->val]++;
            cur = cur->next;
        }
        cur = head;
        ListNode* newcur = newhead;
        while (cur)
        {
            if (hash[cur->val] == 1)
            {
                newcur->next = cur;
                newcur = newcur->next;
            }
            cur = cur->next;
        }
        newcur->next = nullptr;
        return newhead->next;
    }
};